/**
 * practice
 */
package com.thinkgem.jeesite.zmis.practice.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.zmis.practice.entity.ZmisPractice;
import com.thinkgem.jeesite.zmis.practice.service.ZmisPracticeService;

/**
 * 顶岗信息登记表Controller
 * @author ll
 * @version 2017-10-11
 */
@Controller
@RequestMapping(value = "${adminPath}/practice/zmisPractice")
public class ZmisPracticeController extends BaseController {

	@Autowired
	private ZmisPracticeService zmisPracticeService;
	
	@ModelAttribute
	public ZmisPractice get(@RequestParam(required=false) String id) {
		ZmisPractice entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = zmisPracticeService.get(id);
		}
		if (entity == null){
			entity = new ZmisPractice();
		}
		return entity;
	}
	
	@RequiresPermissions("practice:zmisPractice:view")
	@RequestMapping(value = {"list", ""})
	public String list(ZmisPractice zmisPractice, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ZmisPractice> page = zmisPracticeService.findPage(new Page<ZmisPractice>(request, response), zmisPractice); 
		model.addAttribute("page", page);
		return "zmis/practice/zmisPracticeList";
	}

	@RequiresPermissions("practice:zmisPractice:view")
	@RequestMapping(value = "form")
	public String form(ZmisPractice zmisPractice, Model model) {
		model.addAttribute("zmisPractice", zmisPractice);
		return "zmis/practice/zmisPracticeForm";
	}

	@RequiresPermissions("practice:zmisPractice:edit")
	@RequestMapping(value = "save")
	public String save(ZmisPractice zmisPractice, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, zmisPractice)){
			return form(zmisPractice, model);
		}
		zmisPracticeService.save(zmisPractice);
		addMessage(redirectAttributes, "保存顶岗信息登记成功");
		return "redirect:"+Global.getAdminPath()+"/practice/zmisPractice/?repage";
	}
	
	@RequiresPermissions("practice:zmisPractice:edit")
	@RequestMapping(value = "delete")
	public String delete(ZmisPractice zmisPractice, RedirectAttributes redirectAttributes) {
		zmisPracticeService.delete(zmisPractice);
		addMessage(redirectAttributes, "删除顶岗信息登记成功");
		return "redirect:"+Global.getAdminPath()+"/practice/zmisPractice/?repage";
	}

}